﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Text;
using System.Data;

namespace IHISCETeim.Web.MachineSys.FXModel
{
    public partial class FXSJZYYQList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看};
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "FXSJZYYQList";
            }


        }

        protected int ShowTab
        {
            get
            {
                return GetRequestValue<int>("ShowTab", 0);

            }
        }
        protected string AliasName
        {
            get
            {
                return GetRequestValue<string>("AliasName", "");

            }
        }
        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return GetRequestValue<string>("orderField", "OverdueNumber");
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return GetRequestValue<string>("orderDirection", "desc");
            }
        }
        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection + " ,AliasName desc");
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            this.AddLog(Permission.查看, GetWhereSql());
        }
        protected string GetWhereSql()
        {
            string wheresql = "";

            //if (LeaseStatus > -1)
            //{
            //    string LeaseStatussql = QueryOperatorsEnumHelper.ConvertCommonOperator("LeaseStatus", QueryOperatorsEnum.等于, LeaseStatus.ToString());
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = LeaseStatussql;
            //    else
            //        wheresql += " and " + LeaseStatussql;
            //}
            //else
            //{
            //    string LeaseStatussql = string.Format("LeaseStatus in ({0})", "0,1,2,3");
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = LeaseStatussql;
            //    else
            //        wheresql += " and " + LeaseStatussql;
            //}

            if (!AliasName.IsEmptyOrNull())
            {
                string aliasNamesql = QueryOperatorsEnumHelper.ConvertCommonOperator("AliasName", QueryOperatorsEnum.等于, AliasName);
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = aliasNamesql;
                else
                    wheresql += " and " + aliasNamesql;
            }

            //if (!LeaseCompany.IsEmptyOrNull())
            //{
            //    string aliasNamesql = QueryOperatorsEnumHelper.ConvertCommonOperator("LeaseCompany", QueryOperatorsEnum.等于, LeaseCompany);
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = aliasNamesql;
            //    else
            //        wheresql += " and " + aliasNamesql;
            //}

            //if (!CustomerName.IsEmptyOrNull())
            //{
            //    string CustomerNamesql = QueryOperatorsEnumHelper.ConvertCommonOperator("CustomerName", QueryOperatorsEnum.包含, CustomerName);
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = CustomerNamesql;
            //    else
            //        wheresql += " and " + CustomerNamesql;
            //}


            //if (!SerialNumber.IsEmptyOrNull())
            //{
            //    string SerialNumbersql = QueryOperatorsEnumHelper.ConvertCommonOperator("SerialNumber", QueryOperatorsEnum.包含, SerialNumber);
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = SerialNumbersql;
            //    else
            //        wheresql += " and " + SerialNumbersql;
            //}

            //if (!ContractNum.IsEmptyOrNull())
            //{
            //    string ContractNumsql = QueryOperatorsEnumHelper.ConvertCommonOperator("ContractNum", QueryOperatorsEnum.包含, ContractNum);
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = ContractNumsql;
            //    else
            //        wheresql += " and " + ContractNumsql;
            //}

            //if (!FnncLsId.IsEmptyOrNull())
            //{
            //    string FnncLsIdsql = QueryOperatorsEnumHelper.ConvertCommonOperator("FnncLsId", QueryOperatorsEnum.等于, FnncLsId);
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = FnncLsIdsql;
            //    else
            //        wheresql += " and " + FnncLsIdsql;
            //}

            //if (onlyshowExpiryPeriods > 0)
            //{
            //    string FnncLsIdsql = onlyshowExpiryPeriods == 30 ? QueryOperatorsEnumHelper.ConvertCommonOperator("LExpiryPeriods", QueryOperatorsEnum.大于等于, "3") : QueryOperatorsEnumHelper.ConvertCommonOperator("LExpiryPeriods", QueryOperatorsEnum.等于, onlyshowExpiryPeriods.ToString());
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = FnncLsIdsql;
            //    else
            //        wheresql += " and " + FnncLsIdsql;
            //}

            //if (!string.IsNullOrEmpty(LoansDateFrom))
            //{
            //    string LoansDateFromsql = QueryOperatorsEnumHelper.ConvertCommonOperator("LoansDate", QueryOperatorsEnum.范围, LoansDateFrom + " 00:00:00|" + LoansDateTo + " 23:59:59");
            //    if (string.IsNullOrEmpty(wheresql))
            //        wheresql = LoansDateFromsql;
            //    else
            //        wheresql += " and " + LoansDateFromsql;
            //}

            return wheresql;
        }

        private void DataBind()
        {
            DataTable dtc = null;
            //  sumdt = dtc[1];
            switch (ShowTab)
            {
                case 0:
                    dtc = FXSJZYController.FXSJZYAgentGetByWhere("");
                    //sumdt = dtc[1];
                    this.rpMenu0.DataSource = dtc;
                    this.rpMenu0.DataBind();
                    break;
                case 1:
                    dtc = FXSJZYController.FXSJZYDetailGetPagination(GetWhereSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
                  // sumdt = dtc[1];
                    this.rpMenu1.DataSource = dtc;
                    this.rpMenu1.DataBind();
                    break;               
            }
        }


        protected string GetColumnTitle(int index)
        {
            int day = DateTime.Now.Day;
            List<string> columns = new List<string>();

            if (day <= 18)
            {
                columns.Add(DateTime.Now.AddMonths(-3).Month.ToString());
                columns.Add(DateTime.Now.AddMonths(-2).Month.ToString());
                columns.Add(DateTime.Now.AddMonths(-1).Month.ToString());
            }
            else
            {
                columns.Add(DateTime.Now.AddMonths(-2).Month.ToString());
                columns.Add(DateTime.Now.AddMonths(-1).Month.ToString());
                columns.Add(DateTime.Now.Month.ToString());
            }

            return columns[index - 1] + "月逾期租金";
        }

    }
}